package com.s2.m.btchat;

import java.io.IOException;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.StringItem;

/**
 * Displays information about the applicaion
 * @author Samik
 */
public class About implements CommandListener {

    /**
     * This command is used to go back to the home screen
     */
    private Command backCommand = new Command("Back", Command.BACK, 0);
    /**
     * The parent reference
     */
    BTChat parent;

    /**
     * Creates and displays the abour screen
     * @param parent parent midlet
     */
    public About(BTChat parent) {
        this.parent = parent;
        Form aboutForm = new Form("About");
        try {
            Image icon =
                    Image.createImage("/com/s2/m/btchat/res/img/s2chat42x29.png");
            ImageItem iconItem = new ImageItem(null, icon, Item.LAYOUT_2 | Item.LAYOUT_CENTER | Item.LAYOUT_NEWLINE_AFTER, null);
            aboutForm.append(iconItem);

            String text = "S2 Bluetooth Chat\n\n" +
                    "Version: 1.0 (Alpha)\n" +
                    "Copyright 2009\nSamik Saha\n" +
                    "All Rights Reserved\n";
            StringItem textItem = new StringItem(null, text);
            textItem.setLayout(Item.LAYOUT_2 | Item.LAYOUT_CENTER);
            aboutForm.append(textItem);

            aboutForm.addCommand(backCommand);
            aboutForm.setCommandListener(this);

            //set the form as currently displayed item
            Display.getDisplay(parent).setCurrent(aboutForm);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public void commandAction(Command c, Displayable d) {
        if (c == backCommand) {
            parent.showUI();
        }
    }
}
